extends Node2D

var level_scene=[
	"res://level/level1.tscn",
	"res://level/level2.tscn",
	"res://level/level3.tscn",
	"res://level/level4.tscn"
]
# Called when the node enters the scene tree for the first time.
func _ready():
	
	Event.level_next.connect(level_next)# 这边不需要括号
	Event.level_pre.connect(level_pre)# 这边不需要括号
	pass # Replace with function body.

	
func level_next():  
	InitVariable.level=InitVariable.level+1
	if InitVariable.level==4:
		InitVariable.level=0
	print(InitVariable.level+1)
	print(level_scene[InitVariable.level])
	call_deferred("change_scene")#等待到函数空闲状态时再调用
	
func level_pre():
	InitVariable.level=InitVariable.level-1
	if InitVariable.level==-1:
		InitVariable.level=3
	print(InitVariable.level+1)
	print(level_scene[InitVariable.level])
	call_deferred("change_scene")
	
# 防止connect同时响应时发生的线程冲突

func change_scene():
	get_tree().change_scene_to_file(level_scene[InitVariable.level])
	pass
